package com.pfdu.simplescheduler.event;

import com.pfdu.simplescheduler.node.NodeContext;
import com.pfdu.simplescheduler.schedule.TaskCleaner;
import com.pfdu.simplescheduler.schedule.TaskResetSentinel;
import com.pfdu.simplescheduler.schedule.TaskScheduler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ApplicationStartedListener implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private TaskCleaner taskCleaner;
    @Autowired
    private TaskScheduler taskScheduler;
    @Autowired
    private NodeContext nodeContext;
    @Autowired
    private TaskResetSentinel taskResetSentinel;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        log.info("应用启动监听--" + contextRefreshedEvent.getSource().toString());
        taskScheduler.start();
        taskResetSentinel.start();
        nodeContext.init();
        taskCleaner.start();
    }
}
